package com.nan.gbd.library.sip.account;

import android.text.TextUtils;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * @author hongquan.zhao
 * Create Date:2019/1/7
 * Version:V1.0
 * SipDroid project init param class
 * <p>
 * "serverIp": "192.168.10.223",
 * "serverPort": 8116,
 * "serverId": "41010500002000000001",
 * "serverDomain": "4101050000",
 * "password": "12345678",
 * "deviceName": "甘孜天全线路段-物资厂房02",
 * "userId": "06000000441110000211",
 * "videoChannel": "06000000441110000221",
 * "audioChannel": "06000000441110000222"
 */

public class SipConfig {

    private String serverIp;     // SIP服务器地址
    private int serverPort;      // SIP服务器端口
    private String serverId;     // SIP服务器ID
    private String serverDomain; // SIP服务器域
    private String serverCert;   // SIP服务器证书
    private String password;   // 密码
    private String deviceName;   // 设备名称
    private String userId;   // 用户id
    private String videoChannel;   // 视频通道
    private String audioChannel;   // 音频通道
    private String alarmChannel;   // 报警通道编码ID
    private DevConfig devConfig;

    public SipConfig(JSONObject json) {
        update(json);
    }

    public void update(JSONObject configJSON) {
        if (configJSON == null) {
            return;
        }

        if (configJSON.has("serverId")) {
            setServerId(configJSON.optString("serverId"));
        }
        if (configJSON.has("serverPort")) {
            setServerPort(configJSON.optInt("serverPort"));
        }
        if (configJSON.has("serverIp")) {
            setServerIp(configJSON.optString("serverIp"));
        }
        if (configJSON.has("serverDomain")) {
            setServerDomain(configJSON.optString("serverDomain"));
        }
        if (configJSON.has("serverCert")) {
            setServerCert(configJSON.optString("serverCert"));
        }
        if (configJSON.has("password")) {
            setPassword(configJSON.optString("password"));
        }
        if (configJSON.has("deviceName")) {
            setDeviceName(configJSON.optString("deviceName"));
        }
        if (configJSON.has("userId")) {
            setUserId(configJSON.optString("userId"));
        }
        if (configJSON.has("videoChannel")) {
            setVideoChannel(configJSON.optString("videoChannel"));
        }
        if (configJSON.has("audioChannel")) {
            setAudioChannel(configJSON.optString("audioChannel"));
        }
        if (configJSON.has("alarmChannel")) {
            setAlarmChannel(configJSON.optString("alarmChannel"));
        }
        if (configJSON.has("devConfig")) {
            String dev_config = configJSON.optString("devConfig");
            if (TextUtils.isEmpty(dev_config)) {
                return;
            }
            try {
                JSONObject devSON = new JSONObject(dev_config);
                DevConfig devConfig = new DevConfig(devSON);
                setDevConfig(devConfig);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }

    public String getServerIp() {
        return serverIp;
    }

    public void setServerIp(String serverIp) {
        this.serverIp = serverIp;
    }

    public int getServerPort() {
        return serverPort;
    }

    public void setServerPort(int serverPort) {
        this.serverPort = serverPort;
    }

    public String getServerId() {
        return serverId;
    }

    public void setServerId(String serverId) {
        this.serverId = serverId;
    }

    public String getServerDomain() {
        return serverDomain;
    }

    public void setServerDomain(String serverDomain) {
        this.serverDomain = serverDomain;
    }

    public String getServerCert() {
        return serverCert;
    }

    public void setServerCert(String serverCert) {
        this.serverCert = serverCert;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getDeviceName() {
        return deviceName;
    }

    public void setDeviceName(String deviceName) {
        this.deviceName = deviceName;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getVideoChannel() {
        return videoChannel;
    }

    public void setVideoChannel(String videoChannel) {
        this.videoChannel = videoChannel;
    }

    public String getAudioChannel() {
        return audioChannel;
    }

    public void setAudioChannel(String audioChannel) {
        this.audioChannel = audioChannel;
    }

    public String getAlarmChannel() {
        return alarmChannel;
    }

    public void setAlarmChannel(String alarmChannel) {
        this.alarmChannel = alarmChannel;
    }

    public DevConfig getDevConfig() {
        return devConfig;
    }

    public void setDevConfig(DevConfig devConfig) {
        this.devConfig = devConfig;
    }

    @Override
    public String toString() {
        return "SipConfig{" +
                "serverIp='" + serverIp + '\'' +
                ", serverPort=" + serverPort +
                ", serverId='" + serverId + '\'' +
                ", serverDomain='" + serverDomain + '\'' +
                ", serverCert='" + serverCert + '\'' +
                ", password='" + password + '\'' +
                ", deviceName='" + deviceName + '\'' +
                ", userId='" + userId + '\'' +
                ", videoChannel='" + videoChannel + '\'' +
                ", audioChannel='" + audioChannel + '\'' +
                ", alarmChannel='" + alarmChannel + '\'' +
                ", devConfig=" + devConfig +
                '}';
    }
}
